home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / BOXTEST.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-15  |  3KB  |  103 lines

  1. {--------------------------------------------------------------}
  2. {                          BoxTest                             }
  3. {                                                              }
  4. {              Character box draw demo program                 }
  5. {                                                              }
  6. {                             by Jeff Duntemann                }
  7. {                             Turbo Pascal V5.0                }
  8. {                             Last update 7/14/88              }
  9. {                                                              }
  10. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  11. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  12. {--------------------------------------------------------------}
  13.  
  14. PROGRAM BoxTest;
  15.  
  16. USES Crt;
  17.  
  18. TYPE
  19.   GrafRec = RECORD
  20.               ULCorner,
  21.               URCorner,
  22.               LLCorner,
  23.               LRCorner,
  24.               HBar,
  25.               VBar,
  26.               LineCross,
  27.               TDown,
  28.               TUp,
  29.               TRight,
  30.               TLeft : String[4]
  31.             END;
  32.  
  33.      String80  = String[80];
  34.  
  35.  
  36. VAR
  37.   GrafChars    : GrafRec;
  38.   X,Y          : Integer;
  39.   Width,Height : Integer;
  40.  
  41.  
  42. PROCEDURE DefineChars(VAR GrafChars : GrafRec);
  43.  
  44. BEGIN
  45.   WITH GrafChars DO
  46.     BEGIN
  47.       ULCorner  := Chr(201);
  48.       URCorner  := Chr(187);
  49.       LLCorner  := Chr(200);
  50.       LRCorner  := Chr(188);
  51.       HBar      := Chr(205);
  52.       VBar      := Chr(186);
  53.       LineCross := Chr(206);
  54.       TDown     := Chr(203);
  55.       TUp       := Chr(202);
  56.       TRight    := Chr(185);
  57.       TLeft     := Chr(204)
  58.     END
  59. END;
  60.  
  61.  
  62. PROCEDURE MakeBox(X,Y,Width,Height : Integer;
  63.                   GrafChars        : GrafRec);
  64.  
  65. VAR
  66.   I,J : Integer;
  67.  
  68. BEGIN
  69.   IF X < 0 THEN X := (80-Width) DIV 2;    { Negative X centers box }
  70.   WITH GrafChars DO
  71.     BEGIN                                 { Draw top line }
  72.       GotoXY(X,Y); Write(ULCorner);
  73.       FOR I := 3 TO Width DO Write(HBar);
  74.       Write(URCorner);
  75.                                           { Draw bottom line }
  76.       GotoXY(X,(Y+Height)-1); Write(LLCorner);
  77.       FOR I := 3 TO Width DO Write(HBar);
  78.       Write(LRCorner);
  79.                                           { Draw sides }
  80.       FOR I := 1 TO Height-2 DO
  81.         BEGIN
  82.           GotoXY(X,Y+I); Write(VBar);
  83.           GotoXY((X+Width)-1,Y+I); Write(VBar)
  84.         END
  85.     END
  86. END;
  87.  
  88.  
  89.  
  90. BEGIN
  91.   Randomize;                 { Seed the pseudorandom number generator }
  92.   ClrScr;                    { Clear the entire screen }
  93.   DefineChars(GrafChars);    { Go get box-draw characters for this machine }
  94.   WHILE NOT KeyPressed DO    { Draw boxes until a key is pressed }
  95.     BEGIN
  96.       X := Random(72);       { Get a Random X/Y for UL Corner of box }
  97.       Y := Random(21);
  98.       REPEAT Width := Random(80-72) UNTIL Width > 1;  { Get Random Height & }
  99.       REPEAT Height := Random(25-Y) UNTIL Height > 1; { Width to fit on CRT }
  100.       MakeBox(X,Y,Width,Height,GrafChars);            { and draw it! }
  101.     END
  102. END.
  103.